﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;

namespace Himp.Erp
{
    /// <summary>
    /// 入库记录
    /// </summary>
    public class InboundRec : FullAuditedAggregateRoot<Guid>, IMultiTenant
    {
        /// <summary>
        /// 库存变更类别编码
        /// </summary>
        public string InvChgTypeCode { get; set; }

        /// <summary>
        /// 库存变更类别名称
        /// </summary>
        public string InvChgTypeName { get; set; }

        /// <summary>
        /// 所属仓储Id
        /// </summary>
        public Guid MatlWhseId { get; set; }

        /// <summary>
        /// 物料仓储
        /// </summary>
        public MatlWhse MatlWhse { get; set; }

        /// <summary>
        /// 物料供应商
        /// </summary>
        public Guid MatlSplerId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public MatlSpler MatlSpler { get; set; }

        /// <summary>
        /// 入库状态
        /// </summary>
        public EnumInboundStas InboundStas { get; set; }

        /// <summary>
        /// 订单编号
        /// </summary>
        public string OrdNo { get; set; }

        /// <summary>
        /// 发票号
        /// </summary>
        public string? Invono { get; set; }

        /// <summary>
        /// 随货单号
        /// </summary>
        public string? DyntNo { get; set; }

        /// <summary>
        /// 采购金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal? PurcAmt { get; set; }

        /// <summary>
        /// 折扣率
        /// </summary>
        [Column(TypeName = "decimal(18,2)")]
        public decimal? DiscRate { get; set; }

        /// <summary>
        /// 入库金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal? InboundAmt { get; set; }

        /// <summary>
        /// 开票时间
        /// </summary>
        public DateTime? InvoicingTime { get; set; }

        /// <summary>
        /// 买入时间
        /// </summary>
        public DateTime? PurchaseTime { get; set; }

        /// <summary>
        /// 入库时间
        /// </summary>
        public DateTime InboundTime { get; set; }

        /// <summary>
        /// 入库单明细
        /// </summary>
        public List<InboundDetl> InboundDetls { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Exp { get; set; }

        public Guid? ChkOperId { get; set; }

        public string? ChkOperName { get; set; }

        public DateTime Chktime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Guid? TenantId { get; set; }

        public InboundRec()
        { 
        
        }

        public InboundRec(string invChgTypeCode, string invChgTypeName, Guid matlWhseId
             , Guid matlSplerId, string? invono, string? dyntNo
             , decimal? purcAmt, decimal? discRate, decimal? inboundAmt
             , DateTime? invoicingTime, DateTime? purchaseTime, DateTime? inboundTime, string? exp)
        {
            InvChgTypeCode = invChgTypeCode;
            InvChgTypeName = invChgTypeName;
            MatlWhseId = matlWhseId;
            MatlSplerId = matlSplerId;
            Invono = invono;
            DyntNo = dyntNo;
            PurcAmt = purcAmt;
            DiscRate = discRate;
            InboundAmt = inboundAmt;
            InvoicingTime = invoicingTime;
            PurchaseTime = purchaseTime;
            InboundTime = inboundTime ?? DateTime.Now;
            Exp = exp;
            InboundDetls = new List<InboundDetl>();
        }

        public void SetOrdNo(string ordNo)
        {
            OrdNo = ordNo;
        }

    }
}
